#!/usr/bin/env python
#
# UFPE - CIn
#
# Equipe:
# Andre Braga    - login?
# Andre Guedes   - agl
# David Aragao   - dlla
# Jesus Palencia - jspff

import orkutcrawler
from httpclient import HttpClient

class SocialNetworkNode:

    def __init__(self, uid):
        self.uid = uid


class OrkutNode(SocialNetworkNode):
    def __init__(self, uid, name):
        self.uid = uid
        self.name = name

    def aimOnFriend(self, orkutSession):
        url = "/Profile.aspx?uid=" + self.uid
        self.profile = orkutSession.do_request(url, "orkut")

        url = "/Scrapbook.aspx?uid=" + self.uid
        self.scrapbook = orkutSession.do_request(url, "orkut")

        url = "/ProfileT.aspx?uid=" + self.uid
        self.testimonials = orkutSession.do_request(url, "orkut")

    def aimOnTarget(self, orkutSession):
        url = "/Profile.aspx?uid=" + self.uid
        self.profile = orkutSession.do_request(url, "orkut")

        url = "/ProfileC.aspx?uid=" + self.uid
        self.communities = orkutSession.do_request(url, "orkut")

        url = "/FriendsList.aspx?uid=" + self.uid
        self.friends = orkutSession.do_request(url, "orkut")

        url = "/ProfileF.aspx?uid=" + self.uid
        self.fans = orkutSession.do_request(url, "orkut")

        url = "/Scrapbook.aspx?uid=" + self.uid
        self.scrapbook = orkutSession.do_request(url, "orkut")

        url = "/ProfileT.aspx?uid=" + self.uid
        self.testimonials = orkutSession.do_request(url, "orkut")

        url = "/PhotoTag.aspx?uid=" + self.uid
        self.phototag = orkutSession.do_request(url, "orkut")

        url = "/AlbumList.aspx?uid=" + self.uid
        self.photos = orkutSession.do_request(url, "orkut")

        url = "/FavoriteVideos.aspx?uid=" + self.uid
        self.videos = orkutSession.do_request(url, "orkut")


class SocialNetwork:

    def __init__(self, orkutSession, targetUID):
        self.target = OrkutNode(targetUID, "")
        self.target.aimOnTarget(orkutSession)
        self.friends = []
        self.output = []

    def populate(self, orkutSession):
        friendsList = orkutcrawler.get_friends(orkutSession, self.target)
        self.output.append(orkutcrawler.get_scraps(orkutSession, self.target))
        print self.output
        self.output.append(orkutcrawler.get_testimonials(orkutSession, self.target))
        print self.output
        self.output.append(orkutcrawler.get_communities(orkutSession, self.target))
        print self.output
        for friend in friendsList:
            tempFriend = OrkutNode(friend[0], friend[1])
            tempFriend.aimOnFriend(orkutSession)
            self.friends.append(tempFriend)
            testS = orkutcrawler.get_cross_scraps(orkutSession, self.target, tempFriend)
            print "\n\n\n\n#####CROSS SCRAPS: %s" % (testS)
            self.output.append(testS)
            tests = orkutcrawler.get_cross_testimonials(orkutSession, self.target, tempFriend)
            print "\n\n#####CROSS TESTIMONIAL: %s" % (tests)
            self.output.append(tests)
#ADICIONAR CODIGO DO CRAWLER de TESTIMONIAL E SCRAP DO AMIGO
